mui.ready(function() {
	new_element = document.createElement("script");
	new_element.setAttribute("type", "text/javascript");
	new_element.setAttribute("src", "js/des3.js"); // 在这里引入了a.js
	document.body.appendChild(new_element);
	document.querySelector(".agreement").addEventListener("tap", function() {
		mui.openWindow({
			url: '../api/v1/agreement/use',
		});
	})
	var str = window.location.href + '';
	var arr = new Array();
	arr = str.split("userName");
	if(arr.length > 1) {
		var result = arr[1].substring(0);
	}
	document.querySelector(".pMobile").innerHTML = result;
	//截取字符串
	var smsVerifyCode = document.querySelector(".smsVerifyCode");
	smsVerifyCode.addEventListener("tap", function() {
		var reg_phone = document.querySelector(".reg_phone").value;
		var reg1 = /(^1[3|4|5|7|8][0-9]{9}$)/;
		if(reg1.test(reg_phone) == false) {
			mui.toast("请输入正确的手机号码");
			return
		}

		smsVerifyCode.disabled = true;
		var next_time = 60;
		var time_out = setInterval(function() {
			if(next_time == 0) {
				smsVerifyCode.disabled = false;
				smsVerifyCode.innerHTML = "获取验证码";
				clearInterval(time_out);
			} else {
				next_time = next_time - 1;
				smsVerifyCode.innerHTML = next_time;
			}
		}, 1000)
        
        
        
        var verifyCode = document.querySelector('#input_pic_message').value;
		mui.ajax("/api/v1/sms/send", {
			data: {
				paramStr: DES3.encrypt("{'mobile':'"+ reg_phone + "','type':'" + "register" + "','uuid':'" + sessionStorage.uuid + "','verifyCode':'" + verifyCode + "'}")
			},
			dataType: 'json',
			type: 'post',
			success: function(data) {
				mui.toast(data.message);
			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				console.log(type);
			}
		});
	});
	//获取验证码
	document.getElementById("reg").addEventListener("tap", function() {
		var reg_phone = document.querySelector(".reg_phone").value;
		var reg1 = /(^1[3|4|5|7|8][0-9]{9}$)/;
		if(reg1.test(reg_phone) == false) {
			mui.toast("请输入正确的手机号码");
			return
		}
		var reg_password = document.querySelector(".password").value;
		var reg2 = /^[0-9A-Za-z]{6,}$/;
		if(reg2.test(reg_password) == false) {
			mui.toast("请输入6位以上密码");
			return
		}
		var re_password = document.querySelector(".re_password").value;
		if(re_password != reg_password) {
			mui.toast("确认密码错误");
			return
		}
		var temp = document.getElementsByName("sex");
		for(var i = 0; i < temp.length; i++) {
			if(temp[i].checked) {
				var sex = temp[i].value;
			}
		}
		if(sex == undefined) {
			mui.toast("请选择账户类型");
			return
		}
		var pMobile = document.querySelector(".pMobile").value;
		var input_phone_message = document.querySelector("#input_phone_message").value;
		mui.ajax("/api/v1/user/register", {
			data: {
				paramStr: "{userName:" + reg_phone + "','appVer':'h5','password:" + reg_password + ",mobile:" + reg_phone + ",pMobile:'" + pMobile + "',smsVerifyCode:" + input_phone_message + ",sex:" + sex + ",deviceNum:" + "" + ",deviceType:" + "" + ",deviceSize:" + "" + ",deviceOem:" + "" + ",deviceOs:" + "" + "}"
			},
			dataType: 'json',
			type: 'post',
			success : function(data) {
				mui.toast(data.message);
				if(data.code == 200) {
					setTimeout(function() {
						mui.openWindow({
							url: 'http://wx.bshbsh.com/appdownload/',
						});
					}, 3000)
				}
			},
			error : function(xhr , type , errorThrown) {
				//异常处理；
				alert("未知错误");
			}
		});
	});
});